/**
 * Created by SHDN on 2016/10/15.
 */

function setCookie(name, value) {
    var Days = 30; //此 cookie 将被保存 30 天
    var exp = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString()+";path=/";

    location.reload()
}

// 换肤
$("#cskin").click(function () {
    $("#changeskin").css("display", "block");
});
// 默认皮肤
$("#skin-blue").click( function () {
    var url = $(".skin_css").attr("href");
    var href = url.substring(0, url.indexOf('themes')) + 'themes/skin-blue.css';
    $(".skin_css").attr("href", href);
    //   $("#changeskin").css("display", "none");
    setCookie("css-skin", href);
});
// 黄色皮肤
$("#skin-yellow").click( function () {
    var url = $(".skin_css").attr("href");
    var href = url.substring(0, url.indexOf('themes')) + 'themes/skin-yellow.css';
    // $(".skin_css").attr("href", href);
    //    $("#changeskin").css("display", "none");
    setCookie("css-skin", href);
});
// 绿色皮肤
$("#skin-green").click( function () {
    var url = $(".skin_css").attr("href");
    var href = url.substring(0, url.indexOf('themes')) + 'themes/skin-green.css';
    // $(".skin_css").attr("href", href);
    //    $("#changeskin").css("display", "none");
    setCookie("css-skin", href);
});
// 灰色皮肤
$("#skin-grey").click( function () {
    var url = $(".skin_css").attr("href");
    var href = url.substring(0, url.indexOf('themes')) + 'themes/skin-grey.css';
    // $(".skin_css").attr("href", href);
    //    $("#changeskin").css("display", "none");
    setCookie("css-skin", href);
});
function getCookie(name) {
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]);
    return null;
}
var href = getCookie("css-skin")
    var skin = href.substring(href.lastIndexOf("/") + 1, href.lastIndexOf(".css"))
    if (skin == "skin-yellow") {
        $(".btn.blue").addClass("btn yellow")
        $(".portlet.box.blue").addClass("portlet box yellow")
    } else if (skin == "skin-blue") {
        $(".btn.blue").addClass("btn blue")
    } else if (skin==("skin-green")) {
        $(".btn.blue").addClass("btn green")
    } else if (skin==("skin-grey")) {
        $(".btn.blue").addClass("btn grey")
        $(".portlet.box.blue").addClass("portlet box grey")
    }
    $(".skin_css").attr("href", href);


